﻿// HSS.Forms.TriStateTreeNode.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license
// http://www.opensource.org/licenses/mit-license.html
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       TriStateTreeNode.cs
// Author:     HSS\gbanta
// Created:    08/12/2010
// Modified:   12/04/2010
// ----------------------------------------------------------------------------
namespace HSS.Forms
{
	#region TriStateTreeNode
	/// <summary>
	/// Treenode that supports tristate checkboxes
	/// </summary>
	public class TriStateTreeNode : System.Windows.Forms.TreeNode, IStateTreeNode
	{
		#region Constructor
		/// <summary>
		/// Initializes a new instance of the TriStateTreeNode class with the specified label text.
		/// </summary>
		/// <param name="text">The label TriStateTreeNode.Text of the new tree node.</param>
		public TriStateTreeNode(string text)
			: base(text)
		{

		}
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets whether or not the node is checked
		/// </summary>
		new public bool Checked
		{
			get { return _checkState != System.Windows.Forms.CheckState.Unchecked; }
			set { _checkState = System.Windows.Forms.CheckState.Checked; }
		}
		/// <summary>
		/// Gets or sets the CheckState of the Node
		/// </summary>
		public virtual System.Windows.Forms.CheckState CheckState
		{
			get { return _checkState; }
			set { _checkState = value; this.StateImageIndex = (int)value; }
		} System.Windows.Forms.CheckState _checkState;
		#endregion

		#region Methods
		void IStateTreeNode.UpdateState(System.Windows.Forms.TreeViewCancelEventArgs e)
		{
			switch (CheckState)
			{
				case System.Windows.Forms.CheckState.Checked:
					this.CheckState = System.Windows.Forms.CheckState.Indeterminate;
					break;
				case System.Windows.Forms.CheckState.Indeterminate:
					CheckState = System.Windows.Forms.CheckState.Unchecked;
					break;
				case System.Windows.Forms.CheckState.Unchecked:
					CheckState = System.Windows.Forms.CheckState.Checked;
					break;
			}
		}
		#endregion
	}
	#endregion
}